<template>
  <div class="login">
    <div class="con">
      <h3 class="text-center">登录</h3>
      <div>account:{{ account }}</div>
      <el-input v-model="account.username" clearable placeholder="请输入账号"></el-input>
      <el-input v-model="account.password" clearable placeholder="请输入密码" show-password></el-input>
      <div class="text-center">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex"
import { requserlogin } from "../../http/api"
import { successAlert } from "../../utils/alert"
export default {
  data() {
    return {
      account: {
        username: "",
        password: ""
      }

    }
  },
  methods: {
    ...mapActions({
      changeUser:"changeUser"
    }),
    login() {
      requserlogin(this.account).then(res => {
        console.log(res);
        if (res.data.code == 200) {
          //成功弹窗
          successAlert(res.data.msg)
          //存数据
          this.changeUser(res.data.list)
          //跳转页面
          this.$router.push("/")
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
@import url(../../less/index.less);
.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @light, @primary);
  .con {
    width: 350px;
    background: #fff;
    padding: @padding;
    border-radius: @padding;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    h3 {
      margin: @padding 0;
    }
  }
  .el-input {
    margin-bottom: @margin;
  }
}
</style>